home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / cppcom.zip / TIMER.CPP < prev    next >
C/C++ Source or Header  |  1991-05-25  |  2KB  |  101 lines

  1. // Copyright ***********************************************************
  2. //
  3. //     The information in this file is copyright 1991 by David Orme.
  4. //
  5. //        Anyone may use this information for any purpose as long as he takes
  6. //        responsability for any and all libility incurred from its use
  7. //        or misuse and acknowledges its use in the user documentation.  This
  8. //        information is provided AS IS with no warrenty of any kind, either
  9. //        expressed or implied.
  10. //
  11. // End *****************************************************************
  12.  
  13.  
  14. // Contents ************************************************************
  15. //
  16. //        Timer::Timer()
  17. //        Timer::~Timer()
  18. //        Timer::NewTimer()
  19. //
  20. // Description
  21. //
  22. //        The Timer class implements a hardware-based background timer.
  23. //        Note that all instances of this class reference the _same_ timer
  24. //        ISR.
  25. //
  26. // End *****************************************************************
  27.  
  28.  
  29. // Interface Dependencies ----------------------------------------------
  30.  
  31. #ifndef __TIMER_H
  32. #include "timer.h"
  33. #endif
  34.  
  35.  
  36. // Implementation Dependencies -----------------------------------------
  37.  
  38. #ifndef __DOS_H
  39. #include <dos.h>
  40. #define __DOS_H
  41. #endif
  42.  
  43.  
  44. // Global Variables ----------------------------------------------------
  45.  
  46. volatile unsigned long Timer::ticker = 0l;
  47. void interrupt (far * Timer::oldtimer)(...) = 0;
  48.  
  49.  
  50. // Constructor //
  51.  
  52. Timer::Timer()
  53.  
  54. // Summary -------------------------------------------------------------
  55. //
  56. //        Initialize the new timer interrupt handler
  57. //
  58. // End -----------------------------------------------------------------
  59.  
  60. {
  61.     ticker = 0l;
  62.     oldtimer = getvect(TIMER);
  63.     setvect(TIMER, Timer::NewTimer);
  64. }
  65.  
  66.  
  67.  
  68. // Destructor //
  69.  
  70. Timer::~Timer()
  71.  
  72. // Summary --------------------------------------------------------------
  73. //
  74. //        Restore the old timer interrupt in the chain
  75. //
  76. // End ------------------------------------------------------------------
  77.  
  78. {
  79.     setvect(TIMER, oldtimer);
  80. }
  81.  
  82.  
  83.  
  84. // ISR //
  85.  
  86. void interrupt far Timer::NewTimer(...)
  87.  
  88. // Summary --------------------------------------------------------------
  89. //
  90. //        After chaining to the old interrupt handler, decrement our
  91. //        counter if it is greater than 0.
  92. //
  93. // End ------------------------------------------------------------------
  94.  
  95. {
  96.     (*oldtimer)();
  97.     if (ticker > 0l)
  98.     --ticker;
  99. }
  100.  
  101.